/*
 * ListAst.cpp
 *
 *  Created on: 6 Dec 2010
 *      Author: kn308
 */

#include <MAlice/Parser/location.hh>
#include <MAlice/Ast/ListAst.h>

namespace MAlice
{

ListAst::ListAst(location loc) : ExpressionAst(loc),
	mChildren()
{
	MALICE_TRACE;
}

ListAst::ListAst(location loc, Ast* child) : ExpressionAst(loc),
	mChildren(1, child)
{
	MALICE_TRACE;
}

ListAst::ListAst(location loc, const vector<Ast*>& children) : ExpressionAst(loc),
	mChildren(children)
{
	MALICE_TRACE;
}

ListAst::~ListAst()
{
	MALICE_TRACE;
}


ListAst* ListAst::adoptFirst(Ast* child)
{
	mChildren.insert(mChildren.begin(), child);
	return this;
}

ListAst* ListAst::adopt(Ast* child)
{
	mChildren.push_back(child);
	return this;
}


llvm::Value* ListAst::generate()
{
	MALICE_TRACE;
#	ifndef NDEBUG
	cout << "ListAst::generate() : " << mChildren.size() << endl;
#	endif

	Value* value = NULL;
	vector<Ast*>::iterator i = mChildren.begin();
	vector<Ast*>::iterator e = mChildren.end();
	for (int index = 0; i != e; i++, index++)
	{
		value = (*i)->generate();
	}

	return value;
}

}
